#include <iostream>
#include <vector>
using namespace std;
class Apple
{
    public:
    int bid;
    string id;
    int weight;
    int diameter;
    Apple()
    {
        
    }
    Apple(int pbid,string pid,int pweight, int pdiameter)
    {
        bid = pbid;
        id = pid;
        weight = pweight;
        diameter = pdiameter;
    }
}; 
istream & operator>>(istream & in, Apple & a)
{
    in>>a.bid>>a.id>>a.weight>>a.diameter;
    return in;
}
ostream & operator<<(ostream & out, Apple & a)
{
    out<<a.bid<<" "<<a.id<<" "<<a.weight<<" "<<a.diameter;
    return out;
}
int main()
{
    int n;
    cin>>n;
    vector<Apple> all;
    for(int i = 0; i<n; i++)
    {
        Apple a;
        cin>>a;
        all.push_back(a);
    }
    for(int basket = 1; basket<=999999; basket++)
    {
        int max = 0;
        int maxIndex = 0;
        for(int i = 0; i< all.size(); i++)
        {
            if(all[i].bid == basket && all[i].weight>max)
            {
                max = all[i].weight;
                maxIndex = i;
            }
        }
        if(max > 0)
        {
            cout<<all[maxIndex]<<endl;
        }
    }
}